package com.eshop.modules.user.rest;

import org.springframework.web.bind.annotation.DeleteMapping;
import java.io.Serializable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.eshop.modules.aop.ForbidSubmit;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.validation.annotation.Validated;
import com.eshop.modules.shop.domain.SystemUserLevel;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import io.swagger.annotations.ApiOperation;
import com.eshop.logging.aop.log.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.user.service.dto.SystemUserLevelQueryCriteria;
import com.eshop.modules.user.service.SystemUserLevelService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;

@Api(tags = { "商城:用户等级管理" })
@RestController
@RequestMapping({ "api" })
public class SystemUserLevelController
{
    private final SystemUserLevelService systemUserLevelService;
    
    public SystemUserLevelController(final SystemUserLevelService systemUserLevelService) {
        this.systemUserLevelService = systemUserLevelService;
    }
    
    @Log("查询")
    @ApiOperation("查询")
    @GetMapping({ "/yxSystemUserLevel" })
    @PreAuthorize("hasAnyRole('admin','YXSYSTEMUSERLEVEL_ALL','YXSYSTEMUSERLEVEL_SELECT')")
    public ResponseEntity getYxSystemUserLevels(final SystemUserLevelQueryCriteria criteria, final Pageable pageable) {
        return new ResponseEntity(this.systemUserLevelService.queryAll(criteria, pageable), HttpStatus.OK);
    }
    
    @ForbidSubmit
    @Log("新增")
    @ApiOperation("新增")
    @PostMapping({ "/yxSystemUserLevel" })
    @PreAuthorize("hasAnyRole('admin','YXSYSTEMUSERLEVEL_ALL','YXSYSTEMUSERLEVEL_CREATE')")
    public ResponseEntity create(@Validated @RequestBody final SystemUserLevel resources) {
        return new ResponseEntity(this.systemUserLevelService.save(resources), HttpStatus.CREATED);
    }
    
    @ForbidSubmit
    @Log("修改")
    @ApiOperation("修改")
    @PutMapping({ "/yxSystemUserLevel" })
    @PreAuthorize("hasAnyRole('admin','YXSYSTEMUSERLEVEL_ALL','YXSYSTEMUSERLEVEL_EDIT')")
    public ResponseEntity update(@Validated @RequestBody final SystemUserLevel resources) {
        this.systemUserLevelService.saveOrUpdate(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
    
    @ForbidSubmit
    @Log("删除")
    @ApiOperation("删除")
    @DeleteMapping({ "/yxSystemUserLevel/{id}" })
    @PreAuthorize("hasAnyRole('admin','YXSYSTEMUSERLEVEL_ALL','YXSYSTEMUSERLEVEL_DELETE')")
    public ResponseEntity delete(@PathVariable final Integer id) {
        this.systemUserLevelService.removeById((Serializable)id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
